class Enemy
{
  //Constants
  static final int SPEED_LIMIT = 3;
  
  float px;
  float py;
  float velocityX;
  float velocityY;
  float targetX = 0;
  float targetY = 0;
  boolean hasTarget = false;
  int health = 100;
  
  Enemy(float y)
  {
    px = random(100, width - 100);
    py = y;
    
    // Set start velocity
    velocityX = 0;
    velocityY = 0;
    
    // Set default target
    targetX = random(100, width- 100);
    targetY = height;
  }
  
  float getX()
  {
    return px;
  }
  
  float getY()
  {
    return py;
  }
  
  void setTargetY(float y)
  {
    targetY = y;
  }
  
  void setTargetX(float x)
  {
    targetX = x;
  }
  
  float getTargetX()
  {
    return targetX;
  }
  
  float getTargetY()
  {
    return targetY;
  }
  
  boolean hasTarget()
  {
    return hasTarget;
  }
  
  int getHealth()
  {
    return health;
  }
  
  void setHasTarget(boolean target)
  {
    hasTarget = target;
  }
  
  void looseHealth(float damage)
  {
     health -= damage; 
  }
  
  void Update()
  {
    
    //SEEK N DESTROY
    if(targetX != 0 && targetY != 0)
    {
      if(px < targetX)
      {
        ++velocityX;
      }
      else if(px > targetX)
      {
        --velocityX;
      }
      if(py < targetY)
      {
        ++velocityY;
      }
      else if(py > targetY)
      {
        --velocityY;
      }
    }
    
    //speedl imitsor
    
    if(velocityX > SPEED_LIMIT)
    {
      velocityX = SPEED_LIMIT;
    }
    if(velocityY > SPEED_LIMIT)
    {
      velocityY = SPEED_LIMIT;
    }
    
    if(velocityX < -SPEED_LIMIT)
    {
      velocityX = -SPEED_LIMIT;
    }
    if(velocityY < -SPEED_LIMIT)
    {
      velocityY = -SPEED_LIMIT;
    }
    
    //APPLY VELOCITY
    px += velocityX;
    py += velocityY;
    
  }



}
